#include <iostream>

#include "registry.h"

///====================================== windows dllopen functions
#ifdef _WIN32
#    include <windows.h>
using LibHandle = HMODULE;
constexpr const char* kPlugin = "plugin.dll";
LibHandle load(const char* f) { return LoadLibraryA(f); }
void close(LibHandle h) { FreeLibrary(h); }
///====================================== linux dllopen functions
#else
#    include <dlfcn.h>
using LibHandle = void*;
constexpr const char* kPlugin = "./libplugin.so";
LibHandle load(const char* f) { return dlopen(f, RTLD_LAZY); }
void close(LibHandle h) { dlclose(h); }
#endif

int main()
{
    std::cout << "=== 1. 初始空注册表 ===\n";
    Registry::instance().dump();

    std::cout << "\n=== 2. 加载插件 (" << kPlugin << ") ===\n";
    LibHandle h = load(kPlugin);
    if (!h)
    {
        std::cerr << "无法加载插件\n";
        return 1;
    }

    std::cout << "\n=== 3. 再次 dump, 静态初始化已触发 ===\n";
    Registry::instance().dump();

    close(h);
    return 0;
}